<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="21">
          <div class="grid-content bg-purple-dark">
            <h2 id="logo">
              <i class="el-icon-loading"></i> 物业管理系统
              <i class="el-icon-loading"></i>
            </h2>
          </div>
        </el-col>
        <el-col :span="3">
          <div class="grid-content bg-purple">
            <div>
              <el-row>
                <el-col :span="9">
                  <div class="grid-content bg-purple"></div>
                  <el-avatar
                    src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
                    class="head_img"
                  ></el-avatar>
                </el-col>
                <el-col :span="8">
                  <div class="grid-content bg-purple">
                    <el-dropdown @command="back">
                      <div class="el-dropdown-link">
                        <i class="el-icon-user-solid"></i>
                        {{ user.userName }}
                        <i
                          class="el-icon-arrow-down el-icon--right"
                        ></i>
                      </div>
                      <el-dropdown-menu>
                        <el-dropdown-item disabled>账号ID：{{ user.userId }}</el-dropdown-item>
                        <el-dropdown-item disabled>电话号码：{{ user.tel }}</el-dropdown-item>
                        <el-dropdown-item disabled>email：{{ user.email }}</el-dropdown-item>
                        <el-dropdown-item style="text-align: center;">退出登录</el-dropdown-item>
                      </el-dropdown-menu>
                    </el-dropdown>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="240px" class="main-aside">
        <el-menu
          :default-active="url"
          class="el-menu-vertical-demo"
          background-color="unset"
          text-color="#FFFFFF"
          active-text-color="#FDFE91"
          router
          unique-opened
        >
          <el-menu-item index="/home/homepage" @click="tagPush('/home/homepage', '首页')">
            <i class="el-icon-location"></i>
            <span>首页</span>
          </el-menu-item>
          <el-submenu
            style="padding-left='50px'"
            v-for="(v, i) in titleData"
            :key="i"
            :index="v.url"
          >
            <template slot="title">
              <i :class="v.icon"></i>
              <span>{{ v.tit }}</span>
            </template>
            <el-menu-item-group v-for="w in v.titCont" :key="w.cont">
              <el-menu-item :index="w.url" @click="tagPush(w.url, w.cont)">{{ w.cont }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <div id="background"></div>
        <div>
          <el-tag
            v-for="(v, i) in dynamicTags"
            :key="i"
            closable
            type="info"
            style="color: #47464C;font-weight: 600;"
            :disable-transitions="false"
            @close="handleClose(v)"
            @click="skip(v.url)"
          >{{ v.tit }}</el-tag>
        </div>
        <hr />
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      titleData: [
        {
          tit: '楼栋管理',
          url: '/home/floor',
          icon: 'el-icon-office-building',
          titCont: [
            {
              cont: '楼栋管理',
              url: '/home/floor/loudongguanli'
            }
          ]
        }, {
          tit: '合同管理',
          url: '/home/lease',
          icon: 'el-icon-notebook-2',
          titCont: [
            {
              cont: '租赁管理',
              url: '/home/lease/zulinhetong',
            }
          ]
        }, {
          tit: '收费管理',
          url: '/home/charges',
          icon: 'el-icon-coin',
          titCont: [
            { cont: '物业费管理', url: '/home/charges/property', },
            { cont: '租赁费管理', url: '/home/charges/leasing', },
            { cont: '水电气', url: '/home/charges/utilities', },
            { cont: '押金管理', url: '/home/charges/deposit', },
          ]
        }, {
          tit: '物业维修',
          url: '/home/repair',
          icon: 'el-icon-eleme',
          titCont: [
            { cont: '业主报修', url: '/home/repair/yezhubaoxiu', }
          ]
        }, {
          tit: '会员中心',
          url: '/home/members',
          icon: 'el-icon-trophy',
          titCont: [
            { cont: '会员审核', url: '/home/members/huiyuanshenhe', },
            { cont: '会员管理', url: '/home/members/huiyuanguanli', },
          ]
        }, {
          tit: '财务管理', url: '/home/financial',
          icon: 'el-icon-shopping-bag-1',
          titCont: [
            { cont: '收款流水', url: '/home/financial/shoukuan', },
            { cont: '付款流水', url: '/home/financial/fukuan', },
          ]
        },
        {
          tit: '基础档案', url: '/home/base',
          icon: 'el-icon-menu',
          titCont: [
            { cont: '部门管理', url: '/home/base/department', },
            { cont: '员工管理', url: '/home/base/personnel', },
            { cont: '角色管理', url: '/home/base/role', },
            { cont: '费用标准', url: '/home/base/cost', },
          ]
        },
        {
          tit: '个人中心', url: '/home/center',
          icon: 'el-icon-user-solid',
          titCont: [
            { cont: '我的信息', url: '/home/center/myinformation', },
            { cont: '修改密码', url: '/home/center/password', },
          ]
        },
      ],
      dynamicTags: [{ tit: '首页', url: '/home/homepage' },],
      user: {},
      url: '/home/homepage'
    }
  },
  methods: {
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
    },
    tagPush(v, w) {
      if (sessionStorage.getItem('url')) {
        sessionStorage.removeItem('url')
      }
      sessionStorage.setItem('url', v)
      if (this.dynamicTags.every(item => {
        return item.tit != w && item.url != v;
      })) {
        this.dynamicTags.push({ tit: w, url: v })
        if (sessionStorage.getItem("tag")) {
          sessionStorage.removeItem("tag")
        }
        sessionStorage.setItem('tag', JSON.stringify(this.dynamicTags))
      }
    },
    skip(url) {
      this.$router.push({ path: url })
    },
    back() {
      this.$confirm("是否确定退出登录？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$message({
          type: "success",
          message: `退出登录成功!`,
        });
        sessionStorage.removeItem("user")
        sessionStorage.removeItem("token")
        sessionStorage.removeItem("tag")
        sessionStorage.removeItem("url")
        this.$router.push("/");
      })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出登录",
          });
        });
    },
  },


  created() {
    this.user = JSON.parse(sessionStorage.getItem("user"));
    if (sessionStorage.getItem("tag")) {
      this.dynamicTags = JSON.parse(sessionStorage.getItem("tag"));
    }
    if (sessionStorage.getItem("url")) {
      this.url = sessionStorage.getItem("url");
    }
  },
};
</script>
<style scoped lang="less">
// 布局
.el-header {
  // background-color: #5066e1;
  background-image: url("../assets/images/header.png");
  color: white;
  line-height: 60px;
  .head_img {
    margin-top: 10px;
  }
}
i {
  color: #ffffff;
}
#logo {
  font-size: 30px;
  margin-left: 30px;
}
.el-aside {
  background-image: url("../assets/images/header.png");
}
.el-main {
  position: relative;
  padding-left: 20px;
  background-color: unset;
  overflow: hidden;
  .el-menu-item {
    padding: 5px 40px;
  }
}
#background {
  position: absolute;
  z-index: -99;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("../assets/images/header.png");
  background-size: 100% 100%;
  opacity: 0.1;
}
.el-container {
  height: 100%;
}
// 头像旁边的下拉
.el-dropdown-link {
  cursor: pointer;
  color: white;
}
.el-icon-arrow-down {
  font-size: 12px;
}
// 左边导航栏
.tac {
  width: 100%;
}
a {
  color: unset;
  text-decoration: unset;
}
//内容公共样式
.content_h4 {
  margin: 20px 0;
}
.block {
  text-align: right;
  margin: 20px 0;
}
// 标签
hr {
  margin: 10px 0;
}
.el-tag {
  cursor: pointer;
  margin-right: 10px;
}
</style>
<style lang="less">
* {
  font-size: 15px;
}
.el-submenu__title i {
  color: white;
}
.main-aside .el-menu li .el-submenu__title {
  padding-left: 10px;
}
.main-aside {
  border-top: 5px solid white;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
.el-menu-item-group__title {
  padding: 0;
}
.el-form--inline .el-form-item {
  margin-right: 0;
}
.el-main {
  .el-menu-item {
    padding-left: 20px;
  }
}
</style>
